package com.zhongxi.guoyuan.adapter.beautifulStore;

import android.content.Context;
import android.graphics.Paint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.zhongxi.guoyuan.R;
import com.zhongxi.guoyuan.entity.coinStore.HotGoodsData;
import com.zhongxi.guoyuan.url.Url;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2016/12/19.
 */

public class HotServiceAdapter extends BaseAdapter {

    private Context context;
    private List<HotGoodsData> list;

    public HotServiceAdapter(Context context, List<HotGoodsData> data) {
        this.context = context;
        this.list = data;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.ad_item, null);
            holder.tvTitle = (TextView) convertView.findViewById(R.id.tvTitle);
            holder.tvTime = (TextView) convertView.findViewById(R.id.tvTime);
            holder.tvPrice = (TextView) convertView.findViewById(R.id.tvPrice);
            holder.tvCash = (TextView) convertView.findViewById(R.id.tvCash);
            holder.tvOrign = (TextView) convertView.findViewById(R.id.tvOrign);
            holder.ivImg = (ImageView) convertView.findViewById(R.id.ivImg);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        if (null != list.get(position)) {
            HotGoodsData data = list.get(position);

            if (null != data.getThumbnail() && !"".equals(data.getThumbnail())) {
                Glide.with(context).load(Url.IMG_URL+data.getThumbnail()).placeholder(R.mipmap.iv_loading).fitCenter().into(holder.ivImg);
            }
            if (null != data.getName() && !"".equals(data.getName())) {
                holder.tvTitle.setText(data.getName());
            }else{
                holder.tvTitle.setText("");
            }
            if (null != data.getStatus() && !"".equals(data.getStatus())) {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                String time = sdf.format(new Date(Long.parseLong(data.getStatus())*1000));
                holder.tvTime.setText(time);
            }else{
                holder.tvTime.setText("");
            }
            //去掉美币
//            if (null != data.getInnerprice() && !"".equals(data.getInnerprice())) {
//                holder.tvPrice.setText(data.getInnerprice());
//            }else{
//                holder.tvPrice.setText("");
//            }
            if (null != data.getPrice() && !"".equals(data.getPrice())) {
               // holder.tvCash.setText("美币+"+data.getPrice()+"元");
                holder.tvCash.setText(data.getPrice()+"元");
            }else{
                holder.tvCash.setText("");
            }
            if (null != data.getMarketprice() && !"".equals(data.getMarketprice())) {
                holder.tvOrign.setText("原价："+data.getMarketprice());
                holder.tvOrign.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
            }else{
                holder.tvOrign.setText("原价：");
            }
        }
        return convertView;
    }

    class ViewHolder {
        private TextView tvTitle;
        private TextView tvTime;
        private TextView tvPrice;
        private TextView tvCash;
        private TextView tvOrign;
        private ImageView ivImg;
    }
}
